local CommonOHOH = _G.CommonOHOH;

local Tool=CommonOHOH.load.PublicFuction()
local M = CommonOHOH.class.new(script)

function M.new(self, ...)
	return M(self, ...);
end;

function M.ctor(self)
	self.mActionID=1
	self.mAction={}
	self.mDiconnect={}
end

function M.dtor(self)
	self.mAction={}
	for k,con in pairs(self.mDiconnect) do
		con.Connected=false
		con.Action=nil
		-- con.Disconnect=function()
		-- 	--print("M Destoryed")
		-- end
	end
	self.mDiconnect={}
end

function M.Destroy(self)
	self.mAction={}
	for k,con in pairs(self.mDiconnect) do
		con.Connected=false
		con.Disconnect=function()
			print("M Destoryed")
		end
	end
	self.mDiconnect={}
end

function M.DestoryAllConnect(self)
	self.mActionID=1
	self.mAction={}
	self.mDiconnect={}
end

function M.Connect(self,fuc)
	self.mAction[self.mActionID]=fuc
	local con={
		Id=self.mActionID,
		Connected=true,
		Action=self,
		Disconnect=function(this)
			if this.Action then
				this.Connected=false
				this.Action:Disconnect(this.Id)
				this.Action=nil
			else
				-- print("Action isDestoryed")
			end
		end
	}
	--local con={}
	-- con.Disconnect=Tool.delget(M.Disconnect,self,self.mActionID).invoke
	self.mDiconnect[self.mActionID]=con
	self.mActionID=self.mActionID+1
	return con
end
function M.listenCount(self)
	
	local count=0
	for k,func in pairs(self.mAction) do
		if type(func)=="function" then
			count=count+1
		end
	end
	return count
end

function M.Disconnect(self,id)
	self.mAction[id]=nil
end

function M.Action(self,...)
	local arg={}
	for k,func in pairs(self.mAction) do
		local r=func(...)
		if r~=nil then
			table.insert(arg,r)
		end
	end
	return arg
end




return M
